<template>
  <div>
    <!-- 轮播图区域 -->
    <!-- vant的组件有一个特点 组件名叫 van-abc 就会有一个类名叫van-abc  -->
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="item in swipeList" :key="item.id">
        <van-image :src="'http://liufusong.top:8080' + item.imgSrc" />
      </van-swipe-item>
    </van-swipe>
    <!-- 搜索区域 -->
    <!-- 只要用到插槽，就必须把组件变成双标签 -->
    <van-search
      v-model="value"
      placeholder="请输入小区或地址"
      show-action
      @click.native="$router.push('/city')"
    >
      <template #label>
        <span class="city">{{ city.label }}</span> <span class="line"></span>
      </template>
      <template #action>
        <van-icon name="location-o" size="20" color="#fff" />
      </template>
    </van-search>
    <!-- 导航 -->
    <van-grid :border="false">
      <van-grid-item icon="shop-o" text="整租" />
      <van-grid-item icon="shop-o" text="合租" />
      <van-grid-item icon="shop-o" text="地图找房" />
      <van-grid-item icon="shop-o" text="去出租" />
    </van-grid>
    <!-- 租房小组区域 -->
    <div class="zufang">
      <div class="title">
        <h3>租房小组</h3>
        <a href="#">更多</a>
      </div>
      <div class="content">
        <div class="item" v-for="item in groups" :key="item.id">
          <van-image :src="'http://liufusong.top:8080' + item.imgSrc" />
          <div class="right">
            <p>{{ item.title }}</p>
            <p>{{ item.desc }}</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getSwipeList, getGroups } from '@/api/home'
export default {
  name: 'home-page',
  data() {
    return {
      swipeList: [],
      value: '',
      groups: [],
      city: JSON.parse(window.localStorage.getItem('city')) || {
        label: '上海',
        value: 'AREA|dbf46d32-7e76-1196',
        pinyin: 'shanghai',
        short: 'sh'
      }
    }
  },
  methods: {},
  async created() {
    const res1 = await getSwipeList()
    this.swipeList = res1.body
    const res2 = await getGroups()
    this.groups = res2.body
  }
}
</script>

<style scoped lang="less">
.van-image {
  height: 212px;
  img {
    height: 100%;
  }
}

.van-search {
  position: fixed;
  top: 25px;
  width: 100%;
  background-color: transparent;
}
.city {
  position: relative;
}
.city::after {
  content: '';
  width: 0;
  height: 0;
  display: block;
  border: 6px solid transparent;
  border-top-color: #000;
  position: absolute;
  top: 6px;
  right: -16px;
}

::v-deep .van-grid-item__icon {
  color: #21b97a;
  background-color: rgba(195, 246, 223, 0.5);
  padding: 6px;
  border-radius: 50%;
}
.van-search__label {
  margin-right: 20px;
  .city::after {
    margin-left: 10px;
  }
}
.line {
  width: 1px;
  height: 14px;
  background: #ccc;
  display: inline-block;
  margin-left: 20px;
  position: relative;
  top: 4px;
}

.zufang {
  background-color: #f6f5f6;
  padding: 0 10px;
  .title {
    height: 48px;
    line-height: 48px;
    display: flex;
    justify-content: space-between;
    h3 {
      font-size: 15px;
      color: #333;
    }
    a {
      font-size: 14px;
      color: #787d82;
    }
  }
  .content {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    .item {
      width: 172px;
      height: 60px;
      background-color: #fff;
      margin-bottom: 10px;
      display: flex;
      align-items: center;
      padding-left: 5px;
      .van-image {
        width: 50px;
        height: 50px;
        margin-right: 24px;
      }
      p {
        font-size: 14px;
        color: #333;
      }
    }
  }
}
</style>
